{extend name="public:base2"}
{block name="main"}
<div class="layui-form">
  条件搜索：
  <div class="layui-inline">
    <input class="layui-input" name="start" id="start"  placeholder="请输入开始时间">
  </div>
  <div class="layui-inline">
    <input class="layui-input" name="end" id="end"  placeholder="请输入结束时间">
  </div>
  
  <button class="layui-btn" data-type="reload" lay-filter="submit" lay-submit>搜索</button>
  <button class="layui-btn layui-btn-primary" type="reset" data-type="reload" lay-filter="reset" lay-submit>重置</button>

</div>
<table class="layui-table" lay-data="{height:500,url:'{:Url('jsonbannerlist')}', page:true, id:'videolist'}" lay-filter="table">
  <thead>
    <tr>
      <th lay-data="{field:'bannerid', width:80, sort: true}">ID</th>
      <th lay-data="{field:'px', width:80, sort: true}">排序</th>
      <th lay-data="{field:'src', width:80}">缩略图</th>
      <th lay-data="{field:'link', width:300}">跳转连接</th>
      <th lay-data="{field:'status', width:100}">状态</th>
      <th lay-data="{field:'addtime', width:180, sort: true}">添加时间</th>
      <th lay-data="{fixed: 'right', width:180, align:'center', toolbar: '#barDemo'}">操作</th>
    </tr>
  </thead>
</table>

<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-mini" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
</script>

<script>
layui.use(['table','laydate','form'], function(){
  var table = layui.table;
  var laydate = layui.laydate;
  var form = layui.form;
   laydate.render({
      elem: '#start',
      max: 0
   });
    laydate.render({
      elem: '#end',
      max: 1
   });
   
  var $ = layui.$;

  //搜索
  form.on('submit(submit)', function(data){

    var start=$("input[name='start']").val();
    var end=$("input[name='end']").val();

    table.reload('videolist', {
    where: { 
      start:start,
      end:end
    }
  });

    return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
  });

  //重置
  form.on('submit(reset)', function(data){

    $("input").val("");
    table.reload('videolist', {
      where: { 
        keyword:""
      }
    });
    return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
  });


  table.on('tool(table)', function(obj){
    var data = obj.data;

    if(obj.event === 'del'){
      layer.confirm('真的删除本条数据吗？', function(index){

        $.post("{:Url('bannerdel')}",{'bannerid': data.bannerid},function(data){
           if(data=='1'){
              alert();
              obj.del();
              layer.close(index);
           }else{
             alert("删除失败请重试！");
           }
        })
        
      });
    } else if(obj.event === 'edit'){
        location.href="bannerinfo/bannerid/"+data.bannerid;
    
    }
  });

  //图片查看
  layer.photos({
    photos: 'div'
    ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
  });


});

</script>
{/block}